home *** CD-ROM | disk | FTP | other *** search
- /* Get PET ASCII characters from the source file and convert them
- to True ASCII, then write them to the target file. Stop when an
- EOF (End of File) is encountered.
-
- Called with:
-
- PET-TRUE Pet_ASCII_file True_ASCII_file
-
- Noel Nyman 3/90
-
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <io.h>
-
- char sourcebuf[BUFSIZ * 16]; /* source file buffer */
- char targetbuf[BUFSIZ * 16]; /* target file buffer */
-
- main(argc, argv)
- int argc;
- char *argv[];
-
-
- {
- int c, i=0;
- FILE *source, *target;
- char response='Y';
- char petfile[128], truefile[128];
-
-
- if (argc == 2)
- {
- printf("PET-TRUE: must specify both source and target file\n");
- exit(1);
- }
- else if (argc == 1)
- {
- printf("File name of PET-ASCII file: ");
- gets(petfile);
- printf("File name of destination file: ");
- gets(truefile);
- }
- else
- {
- strcpy(petfile,argv[1]);
- strcpy(truefile,argv[2]);
- }
-
-
- if (access(truefile, 0) == 0) /* does target exist */
- do
- {
- printf("\n\"%s\" already exists - Overwrite (Y/N)? ", truefile);
- response = getchar();
- while (getchar() != '\n')
- { ; }
- response = toupper(response);
- } /* loop until Y or N */
- while (response != 'Y' && response != 'N');
-
- if (response == 'Y') /* overwrite the file */
- {
- if ((source = fopen(petfile, "r")) == NULL)
- printf("PET-TRUE: error opening \"%s\"\n", petfile);
-
- else if ((target = fopen(truefile, "w")) == NULL)
- printf("PET-TRUE: error opening \"%s\"\n", truefile);
-
- else
- {
- setvbuf( source, sourcebuf, _IOFBF, sizeof( sourcebuf ) );
- setvbuf( target, targetbuf, _IOFBF, sizeof( targetbuf ) );
-
- printf("Working .");
- while ((c = getc(source)) != EOF)
- {
- if isupper(c)
- putc(tolower(c), target);
-
- else if (c == 13) /* handle single return */
- putc('\n', target);
-
- else
- putc(((c>=193)&(c<=218)?(c-=128):c),target);
-
- if (++i > 256)
- {
- i = 0;
- printf(".");
- }
- }
- fclose(source);
- fclose(target);
- printf("\n");
- }
- }
- }
-
-
-